package com.bishe.demo.modules.other.controller;

import com.bishe.demo.modules.common.entity.ResultEntity;
import com.bishe.demo.modules.common.entity.SearchBean;
import com.bishe.demo.modules.other.entity.Message;
import com.bishe.demo.modules.other.service.MessageService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @PostMapping(value = "/message", consumes = "application/json")
    ResultEntity<Message> insertMessage(@RequestBody Message message) {
        return messageService.insertMessage(message);
    }

    @PutMapping(value = "/message", consumes = "application/json")
    ResultEntity<Message> updateMessage(@RequestBody Message message) {
        return messageService.updateMessage(message);
    }

    @DeleteMapping("/message/{messageId}")
    ResultEntity<Message> deleteMessageByMessageId(@PathVariable int messageId) {
        return messageService.deleteMessageByMessageId(messageId);
    }

    @GetMapping("/message/{messageId}")
    Message getMessageByMessageId(@PathVariable int messageId) {
        return messageService.getMessageByMessageId(messageId);
    }

    @GetMapping("/messages/{userId}")
    List<Message> getMessagesByUserId(@PathVariable int userId) {
        return messageService.getMessagesByUserId(userId);
    }

    @GetMapping("/messages/v2/{sceneryId}")
    List<Message> getMessagesBySceneryId(@PathVariable int sceneryId) {
        return messageService.getMessagesByUserId(sceneryId);
    }

    @PostMapping(value = "/messages", consumes = "application/json")
    PageInfo<Message> getMessagesBySearchBean(@RequestBody SearchBean searchBean) {
        return messageService.getMessagesBySearchBean(searchBean);
    }
}
